/*
 * @Author: liuzehai
 * @Date: 2021-05-14 10:11:28
 * @LastEditTime: 2021-05-14 19:02:18
 * @LastEditors: liuzehai
 * @FilePath: party-platform/src/api/statistical.js
 * @function: 统计API
 */
import request from '@/utils/request';

//  文件下载接口
export function formidableUtil(res, fileName){
  let blob = new Blob([res],{type: "application/vnd.ms-excel"})
  fileName = fileName || '下载.png';
  if ('download' in document.createElement('a')) {
    // 非IE下载
    const elink = document.createElement('a')
    elink.download = fileName
    elink.style.display = 'none'
    elink.href = URL.createObjectURL(blob)
    document.body.appendChild(elink)
    elink.click()
    URL.revokeObjectURL(elink.href) // 释放URL 对象
    document.body.removeChild(elink)
  } else {
    // IE10+下载
    navigator.msSaveBlob(blob, fileName)
  }
}
// 小微企业统计分页查询
const microEnterpriseStatistical = (params) => request({
    url: 'party/microEnterpriseStatistical/page',
    params,
  });
  // 获取当前人的部门数据
const getCurrentTreeList = (params) => request({
  url: 'audit/dept/currentTree',
  params,
});
// 个体工商统计分页查询
const individualStatistical = (params) => request({
  url: 'party/individualStatistical/page',
  params,
});
// 专业市场分页查询
const specializedMarket = (params) => request({
  url: 'party/specializedMarket/page',
  params,
});
//小微企业统计信息导出
function exportmicroEnterpriseStatistical(data) {
  return request({
    url: 'party/microEnterpriseStatistical/export',
    method: 'post',
    data,
    responseType: 'blob'
  }).then(res => {
    formidableUtil(res,'小微私营企业统计信息.xls')
  });
}
//个体工商户统计信息导出
function exportindividualStatistical(data) {
  return request({
    url: 'party/individualStatistical/export',
    method: 'post',
    data,
    responseType:'blob'
  })
}
//专业市场统计信息导出
function exportspecializedMarket(data) {
  return request({
    url: 'party/specializedMarket/export',
    method: 'post',
    data,
    responseType: 'blob'
  }).then(res => {
    formidableUtil(res,'专业市场统计信息.xls')
  });
}
export default {
    microEnterpriseStatistical,
    getCurrentTreeList,
    individualStatistical,
    specializedMarket,
    exportmicroEnterpriseStatistical,
    exportindividualStatistical,
    exportspecializedMarket
}
  
